package com.xique.park.api.factory;

import com.xique.common.core.domain.R;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.park.api.RemoteParkCarService;
import com.xique.park.api.request.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 车辆管理服务错误降级处理类
 *
 * @author WLD
 */
@Slf4j
@Component
public class RemoteParkCarServiceFallbackFactory implements FallbackFactory<RemoteParkCarService> {

    @Override
    public RemoteParkCarService create(Throwable cause) {
        log.error("车辆管理服务调用失败:{}", cause.getMessage());
        return new RemoteParkCarService() {
            @Override
            public R<String> removeBlackExpire() {
                return R.fail("删除黑名单车辆失败" + cause.getMessage());
            }

            @Override
            public R<String> downEnableBlackCar() {
                return R.fail("下发到了启用日期的黑名单车辆失败" + cause.getMessage());
            }

            @Override
            public AjaxResult simpleParkCarList(RemoteParkCarRequest request) {
                return AjaxResult.error("查询车辆列表失败" + cause.getMessage());
            }

            @Override
            public AjaxResult getCarList(RemoteGetCarListRequest request) {
                return AjaxResult.error("获取车辆列表信息失败" + cause.getMessage());
            }

            @Override
            public AjaxResult getMngTypeList(Long parkId) {
                return AjaxResult.error("获取车辆管理类型列表信息失败" + cause.getMessage());
            }

            @Override
            public AjaxResult addBlack(RemoteBlackCarRequest request) {
                return AjaxResult.error("车辆拉黑失败" + cause.getMessage());
            }

            @Override
            public AjaxResult removeBlack(Long carId, Long parkId) {
                return AjaxResult.error("车辆移除黑名单失败" + cause.getMessage());
            }


            @Override
            public AjaxResult removeCar(Long carId, Long parkId) {
                return AjaxResult.error("删除车辆失败" + cause.getMessage());
            }


            @Override
            public AjaxResult updateCar(RemoteParkCarEditRequest request) {
                return AjaxResult.error("修改车辆失败" + cause.getMessage());
            }


            @Override
            public AjaxResult addCar(RemoteParkCarAddRequest request) {
                return AjaxResult.error("新增车辆失败" + cause.getMessage());
            }
        };
    }

}
